package com.walker.component.utils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import org.apache.commons.lang.StringUtils;

public class DateUtils {
	public final static String FORMAT_STRING = "yyyy-MM-dd HH:mm:ss";
	public static String getDefaultDateTime(String dateStr){
		if(StringUtils.isNotBlank(dateStr)){
			return dateStr;
		}
		Date date=new Date();
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		return sdf.format(date);
	}
	
	public static long str2DateMilliseconds(String dateString) {
		return str2DateMilliseconds(dateString, FORMAT_STRING);
	}
	
	public static long str2DateMilliseconds(String dateString,String dateFormat) {
		try {
			SimpleDateFormat simpleDateFormat = new SimpleDateFormat(dateFormat);
			Date date=simpleDateFormat.parse(dateString);
			return date.getTime();
		}
		catch (ParseException e) {
			throw new RuntimeException("时间转化格式错误!" + "[dateString=" + dateString + "]" + "[FORMAT_STRING=" + FORMAT_STRING + "]");
		}
	}
}
